package m.jclecai.com.utils;

import com.google.gson.JsonObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Dinosa on 2017/12/15.
 * 走势图的工具类；
 * 将走势图与对应的中奖号码分开；
 */

public class LotteryTrendUtils {


    String lotteryid;
    JsonObject ifl;
    String hixId;
    String idx;

    public LotteryTrendUtils(String lotteryId,JsonObject ifl,String hixId,String idx) {
        this.lotteryid=lotteryId;
        this.ifl=ifl;
        this.hixId=hixId;
        this.idx=idx;
    }

    /**
     * 这里我们要做一个操作就是返回当前区域中奖的号码的位置的集合
     * @return
     */
    public  List<Integer> getAwardBallList() {
        ArrayList<Integer> integers = new ArrayList<>();

        if ("19".equals(lotteryid)) {
            //这里表示大乐透
            return createDLTAwardBallList(ifl);
        } else if ("16".equals(lotteryid)) {
            //双色球
            return createSSQAwardBallList(ifl);
        } else if ("17".equals(lotteryid)) {
            //七乐彩；
            return createQLCAwardBallList(ifl);
        } else if("18".equals(lotteryid)){
            //七星彩
            return createQXCAwardBallList(ifl);
        }else if("2".equals(lotteryid)){
            //排列三；
            return ceratePlsAwardBallList(ifl);
        }else if("13".equals(lotteryid)){
            //排列五
            return createPlwAwardBallList(ifl);
        }else if("1".equals(lotteryid)){
            //福彩3D
            return create3DAwardBallList(ifl);
        }else if(
                "10".equals(lotteryid)||
                "24".equals(lotteryid)||
                "27".equals(lotteryid)||
                "28".equals(lotteryid)||
                "8".equals(lotteryid)||
                "29".equals(lotteryid)||
                "22".equals(lotteryid)||
                "9".equals(lotteryid)
                ){

            //11选五系列
            return create11Xuan5AwardBallList(ifl);
        }else if("3".equals(lotteryid)){
            //重庆时时彩
            return createSSCAwardBallList(ifl);
        }else if(
                "35".equals(lotteryid)||
                "32".equals(lotteryid)||
                "33".equals(lotteryid)||
                "34".equals(lotteryid)
                ){

            return createKSAwardBallList(ifl);
        }else {
            //默认的处理方式；
            return createAwardBallList(ifl);
        }
    }

    private List<Integer> createKSAwardBallList(JsonObject ifl) {
        ArrayList<Integer> ballList = new ArrayList<>();
        String lottery_num = ifl.get(hixId).getAsString();
        int position = Integer.parseInt(lottery_num)-1;
        ballList.add(position);
        return ballList;
    }

    private List<Integer> createSSCAwardBallList(JsonObject ifl) {
        //这里是时时彩的操作；
        ArrayList<Integer> ballList = new ArrayList<>();
        String lottery_num = ifl.get(idx).getAsString();
        int position = Integer.parseInt(lottery_num);
        ballList.add(position);
        return ballList;
    }

    private List<Integer> create11Xuan5AwardBallList(JsonObject ifl) {

        ArrayList<Integer> ballList = new ArrayList<>();
        String lottery_num = ifl.get(hixId).getAsString();
        int position = Integer.parseInt(lottery_num)-1;
        ballList.add(position);
        return ballList;
    }

    private List<Integer> create3DAwardBallList(JsonObject ifl) {
        ArrayList<Integer> ballList = new ArrayList<>();
        String lottery_num = ifl.get(idx).getAsString();
        int position = Integer.parseInt(lottery_num);
        ballList.add(position);
        return ballList;
    }

    /**
     * 这里是排列五的操作；
     * @param ifl
     * @return
     */
    private List<Integer> createPlwAwardBallList(JsonObject ifl) {
        ArrayList<Integer> ballList = new ArrayList<>();
        String lottery_num = ifl.get(idx).getAsString();
        int position = Integer.parseInt(lottery_num);
        ballList.add(position);
        return ballList;
    }


    private List<Integer> ceratePlsAwardBallList(JsonObject ifl) {
        ArrayList<Integer> ballList = new ArrayList<>();
        String lottery_num = ifl.get(hixId).getAsString();
        int position = Integer.parseInt(lottery_num);
        ballList.add(position);
        return ballList;
    }

    //七星彩；
    private List<Integer> createQXCAwardBallList(JsonObject ifl) {
        ArrayList<Integer> ballList = new ArrayList<>();
        String lottery_num = ifl.get(idx).getAsString();
        int position = Integer.parseInt(lottery_num);
        ballList.add(position);
        return ballList;
    }

    /**
     * 这里我们是做默认的处理方法方式
     * @param ifl
     * @return
     */
    private List<Integer> createAwardBallList(JsonObject ifl) {
        ArrayList<Integer> ballList = new ArrayList<>();
        String lottery_num = ifl.get(hixId).getAsString();
        int position = Integer.parseInt(lottery_num);
        ballList.add(position);
        return ballList;
    }

    /**
     * 七乐彩的操作；
     * @return
     */
    private List<Integer> createQLCAwardBallList(JsonObject ifl) {

        ArrayList<Integer> redBallList=new ArrayList<>();
        ArrayList<Integer> ballList=new ArrayList<>();

        String num_info1 = ifl.get("num_info1").getAsString();
        String num_info2 = ifl.get("num_info2").getAsString();
        String num_info3 = ifl.get("num_info3").getAsString();
        String num_info4 = ifl.get("num_info4").getAsString();
        String num_info5 = ifl.get("num_info5").getAsString();
        String num_info6 = ifl.get("num_info6").getAsString();
        String num_info7 = ifl.get("num_info7").getAsString();

        redBallList.add(Integer.parseInt(num_info1)-1);
        redBallList.add(Integer.parseInt(num_info2)-1);
        redBallList.add(Integer.parseInt(num_info3)-1);
        redBallList.add(Integer.parseInt(num_info4)-1);
        redBallList.add(Integer.parseInt(num_info5)-1);

        redBallList.add(Integer.parseInt(num_info6)-1);
        redBallList.add(Integer.parseInt(num_info7)-1);

        if(idx.equals("area1")){
            //红一
            return getAreaPositionList(0,9,redBallList);
        }else if(idx.equals("area2")){
            //红二
            return getAreaPositionList(10,19,redBallList);
        }else if(idx.equals("area3")){
            //红三
            return getAreaPositionList(20,29,redBallList);
        }
        return ballList;
    }

    /**
     * 七乐彩的选中小球的数量；
     * @param ifl
     * @return
     */
    private List<Integer> createDLTAwardBallList(JsonObject ifl) {

        //这里我们要做的就是双色球的返回值的第一个操作；
        ArrayList<Integer> ballList = new ArrayList<>();

        ArrayList<Integer> redBallList=new ArrayList<>();
        ArrayList<Integer> blueBallList=new ArrayList<>();

        String num_info1 = ifl.get("num_info1").getAsString();
        String num_info2 = ifl.get("num_info2").getAsString();
        String num_info3 = ifl.get("num_info3").getAsString();
        String num_info4 = ifl.get("num_info4").getAsString();
        String num_info5 = ifl.get("num_info5").getAsString();
        String num_info6 = ifl.get("num_info6").getAsString();
        String num_info7 = ifl.get("num_info7").getAsString();

        redBallList.add(Integer.parseInt(num_info1)-1);
        redBallList.add(Integer.parseInt(num_info2)-1);
        redBallList.add(Integer.parseInt(num_info3)-1);
        redBallList.add(Integer.parseInt(num_info4)-1);
        redBallList.add(Integer.parseInt(num_info5)-1);

        blueBallList.add(Integer.parseInt(num_info6)-1);
        blueBallList.add(Integer.parseInt(num_info7)-1);

        //判断是红球还是篮球；
        if(idx.equals("area1")){
            //红一
            return getAreaPositionList(0,11,redBallList);
        }else if(idx.equals("area2")){
            //红二
            return getAreaPositionList(12,23,redBallList);
        }else if(idx.equals("area3")){
            //红三
            return getAreaPositionList(24,34,redBallList);
        }else if(idx.equals("back")){
            //篮区
            return blueBallList;
        }
        return ballList;
    }


    private List<Integer> createSSQAwardBallList(JsonObject ifl) {
        //这里我们要做的就是双色球的返回值的第一个操作；
        ArrayList<Integer> ballList = new ArrayList<>();

        ArrayList<Integer> redBallList=new ArrayList<>();
        ArrayList<Integer> blueBallList=new ArrayList<>();

        String num_info1 = ifl.get("num_info1").getAsString();
        String num_info2 = ifl.get("num_info2").getAsString();
        String num_info3 = ifl.get("num_info3").getAsString();
        String num_info4 = ifl.get("num_info4").getAsString();
        String num_info5 = ifl.get("num_info5").getAsString();
        String num_info6 = ifl.get("num_info6").getAsString();
        String num_info7 = ifl.get("num_info7").getAsString();

        redBallList.add(Integer.parseInt(num_info1)-1);
        redBallList.add(Integer.parseInt(num_info2)-1);
        redBallList.add(Integer.parseInt(num_info3)-1);
        redBallList.add(Integer.parseInt(num_info4)-1);
        redBallList.add(Integer.parseInt(num_info5)-1);
        redBallList.add(Integer.parseInt(num_info6)-1);

        blueBallList.add(Integer.parseInt(num_info7)-1);


        //判断是红球还是篮球；
        if(idx.equals("area1")){
            //红一
            return getAreaPositionList(0,10,redBallList);
        }else if(idx.equals("area2")){
            //红二
            return getAreaPositionList(11,21,redBallList);
        }else if(idx.equals("area3")){
            //红三
            return getAreaPositionList(22,32,redBallList);
        }else if(idx.equals("num_info7")){
            //篮区
            return blueBallList;
        }
        return ballList;
    }

    public List<Integer> getAreaPositionList(int start,int end,List<Integer> awardList){
        //这里我们是将符合要求的中奖号码的位置返回
        ArrayList<Integer> integers = new ArrayList<>();

        for (Integer integer : awardList) {
            //将符合要求的位置添加到一个集合中；
            if(integer>=start && integer<=end){
                integers.add(integer);
            }
        }
        return integers;
    }

}
